package net.maergaiyun.service.impl;

import lombok.extern.slf4j.Slf4j;

import net.maergaiyun.manager.ProductManager;
import net.maergaiyun.model.ProductDO;
import net.maergaiyun.service.ProductService;

import net.maergaiyun.vo.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductManager productManager;


    @Override
    public List<ProductVO> list() {
        List<ProductDO> productDOList = productManager.list();
        List<ProductVO> productVOList = productDOList.stream().map(obj -> beanProcess(obj)).collect(Collectors.toList());
        return productVOList;
    }

    @Override
    public ProductVO findDetailById(Long productId) {
        ProductDO productDO = productManager.findDetailById(productId);
        ProductVO productVO = beanProcess(productDO);
        return productVO;
    }

    private ProductVO beanProcess(ProductDO productDO) {
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(productDO, productVO);
        return productVO;
    }
}
